/**
 * Created by Administrator on 2018-07-23.
 * 航班动态
 */
define(function (require,exports,module) {
    var sTpl = require("./flightDynamic.html");
    require("./flightDynamic.css");
    require("../../../lib/fullcalendar/moment.min.js");

    var VueComponent = Vue.extend({
        template: sTpl,
        props:['parentData'],
        methods:{

            getCellClass:function (row) {
                if(row.column.label=="保障状态"){
                    return "center-cell";
                }
            },
            tableSort:function(){

            },
            rowClass:function (row, index){
                /*进港未起飞*/
                index = row.index;
                row = row.row;
                if(row.importOrExport=="进港"&&row.flightState=="未起飞"){
                    return "import-no-fly";
                }
                /*进港已起飞未分配机位*/
                if(row.importOrExport=="进港"&&row.flightState=="起飞"&&row.cameraState==null){
                    return "import-fly-no-assigned"
                }
                /*进港已起飞已分配机位*/
                if(row.importOrExport=="进港"&&row.flightState=="起飞"&&row.cameraState=="已分配"){
                    return "import-fly-assigned"
                }
                /*进港到达出港未起飞*/
                if(row.importOrExport=="进港"&&row.flightState=="到达"){
                    return "import-arrive "
                }
                if(row.importOrExport=="出港"&&row.flightState=="未起飞"){
                    return "import-arrive"
                }
                /*出港起飞*/
                if(row.importOrExport=="出港"&&row.flightState=="起飞"){
                    return "export-fly"
                }

                /*延误*/
                if(row.flightState=="延误"){
                    return "delay"
                }

                /*备降返航*/
                if(row.flightState=="备降返航"){
                    return "return-to-the-air"
                }
                console.log(row);


            },

            zeroPadding:function(num, digit) {
                var zero = '';
                for(var i = 0; i < digit; i++) {
                    zero += '0';
                }
                return (zero + num).slice(-digit);
            },
            checkFlightDynamic:function () {
                var $this = this;
                axios.get(basepath+"/api/flightDynamic/query?importOrExport="+
                    $this.importOrExport+
                    "&expectDate="//+moment().format("YYYY-MM-DD")
                ).then(function (response) {
                    console.log(response);
                    $this.tableData=response.data;
                });

            },
            checkImport:function () {
                this.importOrExport="进港";
                this.checkFlightDynamic();
            },
            checkExport:function () {
                this.importOrExport="出港";
                this.checkFlightDynamic();
            },
            checkImportOrExport:function () {
                this.importOrExport="";
                this.checkFlightDynamic();
            }
        },
        mounted:function() {

        },
        watch:{
            tableData:function (nv,ov) {
               this.parentData.dataRefresh(nv);
            }
        },
        data:function(){
            return {
                tableData:[],
                importOrExport:''
            }
        },
        created:function (){
            this.checkFlightDynamic();
            $this=this;
        },
        activated:function () {
            messages.$emit('change','航班动态');
        }

    });

    module.exports = VueComponent;
})
